//
//  DetailsContorller.m
//  QRBuildScan
//
//  Created by gongjie on 12-1-3.
//  Copyright (c) 2012年 __MyCompanyName__. All rights reserved.
//

#import "DetailsContorller.h"
#import "QRImageController.h"
#import "QRnformationController.h"
#import "QRCodeData.h"

@implementation DetailsContorller


@synthesize D_leftbuttn;
@synthesize D_QRCodeData;

//- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
//{
//    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
//    if (self) {
//        // Custom initialization
//    }
//    return self;
//}

- (void)didReceiveMemoryWarning
{
    // Releases the view if it doesn't have a superview.
    [super didReceiveMemoryWarning];
    
    // Release any cached data, images, etc that aren't in use.
}

#pragma mark - View lifecycle

-(id)init
{
    if (self = [super init]) {
        
        D_leftbuttn = [UIButton buttonWithType:UIButtonTypeCustom];
        D_leftbuttn.frame = CGRectMake(10,7, 60, 30);
        [D_leftbuttn setBackgroundImage:[UIImage imageNamed:@"cancel.png"] forState:UIControlStateNormal];
        [D_leftbuttn addTarget:self action:@selector(changhWleft) forControlEvents:UIControlEventTouchUpInside];
        [D_leftbuttn retain];
    }
    return self;
}
-(void)changhWleft
{
    if (D_leftbuttn.superview) {
        [D_leftbuttn removeFromSuperview];
    }
    [self.navigationController popViewControllerAnimated:YES];
}
/*
// Implement loadView to create a view hierarchy programmatically, without using a nib.
- (void)loadView
{
}
*/


// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
- (void)viewDidLoad
{
    [super viewDidLoad];
    [self.view setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:@"tablebg.png"]]];
    D_Tableview = [[UITableView alloc] initWithFrame:CGRectMake(10, 10,300 ,200 ) style:UITableViewStyleGrouped];
    [D_Tableview setBackgroundColor:[UIColor clearColor]];
    [D_Tableview setDelegate:self];
    [D_Tableview setDataSource:self];
    [self.view addSubview:D_Tableview];
}

#pragma mark UITableViewDataSource
- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section
{
    return 4;
}

- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
    UIView* tview = [[[UIView alloc] initWithFrame:tableView.frame] autorelease];
	[tview setBackgroundColor:[UIColor clearColor]];
	[tableView setBackgroundView:tview];
    static NSString *CellIdentifier = @"Cell";
            NSUInteger row = [indexPath row];
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:CellIdentifier];
    if (cell == nil) {
        cell = [[[UITableViewCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:CellIdentifier] autorelease];
        cell.selectionStyle =UITableViewCellSelectionStyleNone;


        switch (row) {
            case 0:
            case 1:
            {
                UILabel* tip1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 80, 18)];
                tip1.tag = 1;
                [tip1 setBackgroundColor:[UIColor clearColor]];
                tip1.font = [UIFont systemFontOfSize:16];
                tip1.textColor = [UIColor blackColor];
                [cell.contentView addSubview:tip1];
                
                UILabel* tip2 = [[UILabel alloc] initWithFrame:CGRectMake(100, 10, 200, 18)];
                tip2.tag = 2;
                [tip2 setBackgroundColor:[UIColor clearColor]];
                tip2.font = [UIFont systemFontOfSize:16];
                tip2.textColor = [UIColor colorWithRed:55/255 green:86/255 blue:129/255 alpha:1.0f];
                [cell.contentView addSubview:tip2];
            }
            break;
            break;
            case 2:
            case 3:
            {
                cell.accessoryType = UITableViewCellAccessoryDisclosureIndicator;
                UILabel* tip1 = [[UILabel alloc] initWithFrame:CGRectMake(20, 10, 150, 18)];
                tip1.tag = 3;
                [tip1 setBackgroundColor:[UIColor clearColor]];
                tip1.font = [UIFont systemFontOfSize:16];
                tip1.textColor = [UIColor blackColor];
                [cell.contentView addSubview:tip1]; 
            }
            break;
        }
        
    }
    UILabel* ilabel = (UILabel*)[cell.contentView viewWithTag:1];
    UILabel* ilabel1 = (UILabel*)[cell.contentView viewWithTag:2];    
    UILabel* ilabel2 = (UILabel*)[cell.contentView viewWithTag:3];
    if (row == 0) {
        [ilabel setText:@"已扫描:"];
        [ilabel1 setText:D_QRCodeData.grouptime];
    }
    else if(row == 1)
    {
        [ilabel setText:@"类型:"];
        [ilabel1 setText:D_QRCodeData.qrtypename];
    }
    else if(row == 2)
    {
        ilabel2.text = @"查看QR图像";
    }
    else
    {
         ilabel2.text = @"QR码信息";
    }
    return cell;
}

#pragma mark UITableViewDelegate
- (CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return 40;
}


- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    [tableView deselectRowAtIndexPath:indexPath animated:YES];
    

    NSUInteger row = [indexPath row];
    if (row == 2) {
        if (D_leftbuttn.superview) {
            [D_leftbuttn removeFromSuperview];
        }
        QRImageController*  QRImage = [[QRImageController alloc] init];
        [QRImage setImageShow:D_QRCodeData.qrcodepath];
        [self.navigationController pushViewController: QRImage animated:YES];
        [ QRImage release];
    }
    else if(row == 3)
    {
        if (D_leftbuttn.superview) {
            [D_leftbuttn removeFromSuperview];
        }
        QRnformationController* QRnformation = [[QRnformationController alloc] init];
        [QRnformation setDizhi:D_QRCodeData.content];
        [self.navigationController pushViewController:QRnformation animated:YES];
        [QRnformation release];
    }

}
- (void)viewDidUnload
{
    [super viewDidUnload];
    // Release any retained subviews of the main view.
    // e.g. self.myOutlet = nil;
}

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
    // Return YES for supported orientations
    return (interfaceOrientation == UIInterfaceOrientationPortrait);
}

@end
